﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;

namespace TBlog.Helpers
{
    public static class MenuItemHelper
    {
        public static string MenuItem(this HtmlHelper helper, string linkText, string actionName, string controllerName)
        {
            string currentControllerName = (string)helper.ViewContext.RouteData.Values["controller"];
            string currentActionName = (string)helper.ViewContext.RouteData.Values["action"];

            var builder = new TagBuilder("li");

            // Add selected class
            if (currentControllerName.Equals(controllerName, StringComparison.CurrentCultureIgnoreCase) && currentActionName.Equals(actionName, StringComparison.CurrentCultureIgnoreCase))
                builder.AddCssClass("current_page_item");
            else
                builder.AddCssClass("page_item");

            // Add link
            builder.InnerHtml = helper.ActionLink(linkText, actionName, controllerName).ToHtmlString();

            //builder.InnerHtml = helper.ActionLink(linkText, actionName, controllerName);
            //return link.Replace(linkText, builder.ToString(TagRenderMode.SelfClosing));
            var ggg = builder.ToString(TagRenderMode.Normal);
            // Render Tag Builder
            return builder.ToString(TagRenderMode.Normal);
        }

    }
}